import {defineStore} from 'pinia'
import {nextTick} from "vue";
import {flattenMenuList} from "../utils";

const menuListStore = defineStore('menuList',{
    state:()=>({
        list:<any>[],
        fullMenuList:<any>[],
        activeMenuInfo:{},
        flattenMenuList:<any>[],
        mainList:[],
        keyPath:[],
        mainLoading: true,
        mainMenuCurrent: <any>[],
        mainMenuLeftPosition: '150px'
    }),
    actions:{
        setMainMenuCurrent(mainMenuCurrentValue:Array<string>){
            this.mainMenuCurrent = mainMenuCurrentValue
        },
        updateList(newMenuList:Array<any>, fn:() => void = ()=>{}){
            this.list = newMenuList
            console.log('list', this.list)
            this.flattenMenuList = flattenMenuList(newMenuList)
            nextTick().then(()=> this.mainLoading = false)
            fn()
        },
        updateFullMenuList(fullMenuList:any){
            this.fullMenuList = fullMenuList
        },
        setMainMenuLeftPosition(position: string){
            this.mainMenuLeftPosition = position
        },
        updateKeyPath(path:[]){
          this.keyPath = path
        },
        setActiveMenuInfo(menuInfo:{}){
            this.activeMenuInfo = menuInfo
        }
    }
})

export default menuListStore